<?php
declare (strict_types = 1);

namespace app\controller;

use app\middleware\Auth as AuthMiddleware;
use app\model\AmForecast;
use think\Request;

class Amyc
{
    protected $middleware = [AuthMiddleware::class];
    private $toast = 'public/toast';
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        //
        return view('index', [
            'list'  =>   AmForecast::withSearch(['id','forecast_type', 'start_issue', 'end_issue','forecast_content', 'iswin'], [
                'id'        =>  request()->param('id'),
                'forecast_type'      =>  request()->param('forecast_type'),
                'start_issue'      =>  request()->param('start_issue'),
                'end_issue'        =>  request()->param('end_issue'),
                'forecast_content'      =>  request()->param('forecast_content'),
                'iswin'   =>  request()->param('iswin')
            ])->paginate([
                'list_rows'     =>  20,
                'query'         =>  request()->param()
            ]),
            'order'         =>  request()->param('start_issue') == 'desc' ? 'asc' : 'desc'
        ]);

    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        //
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request)
    {
        //
    }

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {
        //
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function edit($id)
    {
        //
        return view('edit', [
            'obj'   =>  AmForecast::find($id)
        ]);
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request, $id)
    {
        //
        $data = $request->param();

        return AmForecast::update($data) ? view($this->toast, [
            'infos'     =>  ['恭喜，修改成功~'],
            'url_text'  =>  '返回列表页',
            'url_path'  =>  url('/amyc')
        ]) : '修改失败';
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        //
    }
}
